"""
缓冲区
"""
# 1.
file_target = open("test.txt", 'a')
while True:
    msg = input(">>")
    if not msg:
        break
    file_target.write(msg)
    # file_target.flush()

# 2.
file_target = open("test.txt", 'a', buffering=1)
while True:
    msg = input(">>")  # 回车代表输入完毕,不是换行
    if not msg:
        break
    file_target.write(msg + '\n')

# 3.
file_target = open("test.txt", 'ab', buffering=10)  # 二进制方式
while True:
    msg = input(">>")  # 回车代表输入完毕,不是换行
    if not msg:
        break
    file_target.write(msg.encode())  # 输入的从终端放到缓冲区,检查>=缓冲区大小就刷新
